package com.swl.controller;

import com.swl.pojo.Score;
import com.swl.pojo.User;
import com.swl.service.ScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/score")
public class ScoreController {

    @Autowired
    private ScoreService scoreService;

    @RequestMapping("/insertScore")
    @ResponseBody
    public int insertScore(@RequestParam("userName") String userName){
        System.out.println("--------------执行了insertScore"+userName+"------------");
        return scoreService.insertScore(userName);
    }

    @RequestMapping("/selectByName")
    @ResponseBody
    public Score selectByName(String userName){
        Score score=scoreService.selectByName(userName);
        if (score!=null){
            score.setUser(new User(userName));
        }
        System.out.println(score);
        return score;
    }
    @RequestMapping("/updateScore")
    @ResponseBody
    public int  updateScore(@RequestParam("userName") String userName,@RequestParam("sum")int sum){
        System.out.println("updateScore执行了");
        int i=scoreService.updateScore(userName,sum);
        return i;
    }
}
